package flc.ast.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ToastUtils;
import com.github.gzuliyujiang.wheelpicker.contract.OnDateSelectedListener;
import com.github.gzuliyujiang.wheelpicker.entity.DateEntity;

import flc.ast.R;
import flc.ast.databinding.DialogSelDateBinding;
import stark.common.basic.base.BaseSmartDialog;

public class SelDateDialog extends BaseSmartDialog<DialogSelDateBinding> implements View.OnClickListener {

    public String title;
    private int mYear, mMonth, mDay;

    public SelDateDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean canceledOnTouchOutside() {
        return true;
    }

    @Override
    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_sel_date;
    }

    @Override
    protected void initView(View view) {
        if (title != null) {
            mDataBinding.tvTitle.setText(title);
        }
        mDataBinding.tvCancel.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);

        mDataBinding.dtSelDate.setRange(DateEntity.target(1970, 1, 1), DateEntity.target(2200, 12, 31), DateEntity.today());
        mDataBinding.dtSelDate.setOnDateSelectedListener(new OnDateSelectedListener() {
            @Override
            public void onDateSelected(int year, int month, int day) {
                mYear = year;
                mMonth = month;
                mDay = day;
            }
        });
        mYear = mDataBinding.dtSelDate.getSelectedYear();
        mMonth = mDataBinding.dtSelDate.getSelectedMonth();
        mDay = mDataBinding.dtSelDate.getSelectedDay();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvCancel:
                dismiss();
                break;
            case R.id.tvConfirm:
                dismiss();
                if (listener != null) {
                    listener.selDate(mYear, mMonth, mDay);
                }
                break;
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void selDate(int year, int month, int day);
    }
}
